<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        .data {
            padding: 10px;
        }

        .data .sousuo {
            margin-top: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .data .sousuo input {
            width: 250px;
            height: 30px;
            border-radius: 15px;
            border: 0;
            background-color: rgb(230, 226, 226);
            padding-left: 20px;
        }

        .data .sousuo span {
            color: blue;
        }

        .data .box {
            margin-top: 20px;
        }

        .data .box h4 span {
            color: gray;
            float: right;
            font-size: 12px;
            font-weight: 400;
        }

        .data .box .list {
            font-size: 12px;
            margin-top: 5px;
            width: 100%;
        }

        .data .box .list .wenzi {
            padding: 5px;
            background-color: rgb(205, 205, 205);
            display: inline-block;
            margin: 5px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="data">
            <h3>&lt; 搜索</h3>
            <div class="sousuo">
                <input type="text" placeholder="搜索商家、商品名称" v-model="inputText"><span @click="seach">搜索</span>
            </div>
            <div class="box">
                <h4>历史搜索 <span @click="qingkong">清空</span></h4>
                <div class="list">
                    <div class="wenzi" v-for="(item,index) in tacklist" :key="index">{{ item.name }}</div>
                </div>
            </div>
            <div class="box">
                <h4>搜索发现</h4>
                <div class="list">
                    <span class="wenzi" v-for="(item,index) in tacklist1" :key="index">{{ item.name }}</span>

                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            inputText: '',
            tacklist: [],
            tacklist1: [
                { name: '麻辣烫' },
                { name: '米线' },
                { name: '披萨' },
                { name: '龙虾' },
                { name: '腊八粥' },
                { name: '老八秘制小汉堡' },
            ]

        },
        methods: {
            seach() {
                if (this.inputText) {
                    var obj = { name: this.inputText }
                    this.tacklist.push(obj)
                }
                this.inputText = ''
            },
            qingkong() {
                this.tacklist = []
            }
        }
    })
</script>